﻿namespace HuaWei
{
    using System;

    public static class RMBCapitalization
    {
        private const string botbmnerR = "元拾佰仟万亿京兆垓";
        private const string str = "零壹贰叁肆伍陆柒捌玖";
        private const string str1 = "毫厘分角元拾佰仟万拾佰仟亿拾佰仟万兆拾佰仟万亿京拾佰仟万亿兆垓";

        public static string ConvertDecToUppercaseAmount(string capValue, bool addZero)
        {
            string str = "";
            string str2 = "";
            int num = addZero ? -1 : 0;
            int startIndex = 0;
            int num3 = 3;
            if (Convert.ToInt32(capValue) == 0)
            {
                return "";
            }
            for (int i = 0; i < capValue.Length; i++)
            {
                startIndex = Convert.ToInt32(capValue.Substring(i, 1));
                if (startIndex != 0)
                {
                    str = "零壹贰叁肆伍陆柒捌玖".Substring(startIndex, 1) + "毫厘分角元拾佰仟万拾佰仟亿拾佰仟万兆拾佰仟万亿京拾佰仟万亿兆垓".Substring(num3, 1);
                }
                else
                {
                    if (Convert.ToInt32(capValue.Substring(i)) == 0)
                    {
                        return str2;
                    }
                    if (num != 0)
                    {
                        str = "零";
                    }
                }
                str2 = str2 + str;
                num = startIndex;
                num3--;
                str = "";
            }
            return str2;
        }

        public static string ConvertIntToUppercaseAmount(string capValue)
        {
            string str = "";
            string str2 = "";
            string str3 = "";
            string str4 = "";
            int num = -1;
            int startIndex = 0;
            int num3 = 4;
            if (Convert.ToDouble(capValue) == 0.0)
            {
                return "";
            }
            for (int i = capValue.Length - 1; i >= 0; i--)
            {
                startIndex = Convert.ToInt32(capValue.Substring(i, 1));
                if (num3 > 30)
                {
                    return str2;
                }
                if (startIndex != 0)
                {
                    str = "零壹贰叁肆伍陆柒捌玖".Substring(startIndex, 1) + "毫厘分角元拾佰仟万拾佰仟亿拾佰仟万兆拾佰仟万亿京拾佰仟万亿兆垓".Substring(num3, 1);
                }
                else
                {
                    switch (num3)
                    {
                        case 4:
                            str = "元";
                            break;

                        case 8:
                            str = "万";
                            break;

                        case 12:
                            str = "亿";
                            break;

                        case 0x11:
                            str = "兆";
                            break;

                        case 0x17:
                            str = "京";
                            break;

                        case 30:
                            str = "垓";
                            break;
                    }
                    if (num != 0)
                    {
                        if (str != "")
                        {
                            if (str != "元")
                            {
                                str = str + "零";
                            }
                        }
                        else
                        {
                            str = "零";
                        }
                    }
                }
                if (str2.Length > 0)
                {
                    str4 = str2.Substring(0, 1);
                    str3 = "毫厘分角元拾佰仟万拾佰仟亿拾佰仟万兆拾佰仟万亿京拾佰仟万亿兆垓".Substring(num3, 1);
                    if (("元拾佰仟万亿京兆垓".IndexOf(str4) > 0) && ("元拾佰仟万亿京兆垓".IndexOf(str3) > "元拾佰仟万亿京兆垓".IndexOf(str4)))
                    {
                        str2 = str2.Substring(1);
                    }
                }
                str2 = str + str2;
                num = startIndex;
                num3++;
                str = "";
            }
            return str2;
        }

        public static string smethod(decimal value)
        {
            bool flag2;
            string str = "";
            string str2 = string.Format("{0:f4}", value);
            int index = str2.IndexOf(".");
            bool flag = Convert.ToInt32(str2.Substring(index + 1)) == 0;
            index = (flag2 = str2.Substring(0, 1) == "-") ? (index - 1) : index;
            int startIndex = flag2 ? 1 : 0;
            string capValue = "0";
            string str4 = "0";
            capValue = str2.Substring(startIndex, index);
            if (flag2)
            {
                str4 = str2.Substring(index + 2);
            }
            else
            {
                str4 = str2.Substring(index + 1);
            }
            if (index > 0)
            {
                str = ConvertIntToUppercaseAmount(capValue) + ConvertDecToUppercaseAmount(str4, Convert.ToDouble(capValue) != 0.0);
            }
            else
            {
                str = ConvertIntToUppercaseAmount(str4);
            }
            if (flag2)
            {
                str = "负" + str;
            }
            if (flag)
            {
                str = str + "整";
            }
            return str;
        }
    }
}

